package org.example.mq.demo;

import org.example.mq.mqclient.Channel;
import org.example.mq.mqclient.Connection;
import org.example.mq.mqclient.ConnectionFactory;
import org.example.mq.mqserver.core.ExchangeType;

import java.io.IOException;

public class DemoProducer {
    public static void main(String[] args) throws IOException {
        System.out.println("生产者启动！");

        ConnectionFactory connectionFactory  = new ConnectionFactory();

        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare("testQueue",true,false,false,null);
        channel.exchangeDeclare("testDirectExchange", ExchangeType.DIRECT,true,false,null);
        channel.queueBind("testDirectExchange","testQueue","apple");

        String message = "hello,my mq!";

        boolean ok = channel.basicPublish("testDirectExchange", "apple", null, message.getBytes());
        System.out.println("消息发送，ok="+ok);

        channel.close();
        connection.close();
    }
}
